package xyz.yuanjilu.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.riversoft.weixin.common.menu.Menu;

import xyz.yuanjilu.annotation.SysLog;
import xyz.yuanjilu.entity.WeixinConfigEntity;
import xyz.yuanjilu.service.WeixinConfigService;
import xyz.yuanjilu.utils.PageUtils;
import xyz.yuanjilu.utils.Query;
import xyz.yuanjilu.utils.R;


/**
 * 微信配置
 * 
 * @author CHENJUNFEI
 * @email kkomge@qq.com
 * @date 2017-08-23 11:11:23
 */
@RestController
@RequestMapping("weixinconfig")
public class WeixinConfigController {
	@Autowired
	private WeixinConfigService weixinConfigService;
	
	/**
	 * 列表
	 */
	@RequestMapping("/list")
	@RequiresPermissions("weixinconfig:list")
	public R list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);

		List<WeixinConfigEntity> weixinConfigList = weixinConfigService.queryList(query);
		int total = weixinConfigService.queryTotal(query);
		
		PageUtils pageUtil = new PageUtils(weixinConfigList, total, query.getLimit(), query.getPage());
		
		return R.ok().put("page", pageUtil);
	}
	
	
	/**
	 * 信息
	 */
	@RequestMapping("/info/{id}")
	@RequiresPermissions("weixinconfig:info")
	public R info(@PathVariable("id") Long id){
		WeixinConfigEntity weixinConfig = weixinConfigService.queryObject(id);
		
		return R.ok().put("weixinConfig", weixinConfig);
	}
	
	/**
	 * 保存
	 */
	@SysLog("保存微信配置")
	@RequestMapping("/save")
	@RequiresPermissions("weixinconfig:save")
	public R save(@RequestBody WeixinConfigEntity weixinConfig){
		weixinConfigService.save(weixinConfig);
		
		return R.ok();
	}
	
	/**
	 * 修改
	 */
	@SysLog("修改微信配置")
	@RequestMapping("/update")
	@RequiresPermissions("weixinconfig:update")
	public R update(@RequestBody WeixinConfigEntity weixinConfig){
		weixinConfigService.update(weixinConfig);
		
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@SysLog("删除微信配置")
	@RequestMapping("/delete")
	@RequiresPermissions("weixinconfig:delete")
	public R delete(@RequestBody Long[] ids){
		weixinConfigService.deleteBatch(ids);
		
		return R.ok();
	}
	/**
	 * 信息
	 */
	@RequestMapping("/menus/{id}")
	public R menus(@PathVariable("id") Long id){
		Menu menus = weixinConfigService.getMenus(id);
		
		return R.ok().put("menus", menus);
	}
}
